package cn.tedu.charging.order.controller;


import cn.tedu.charging.order.feign.DeviceClient;
import cn.tedu.charging.order.pojo.param.OrderAddParam;
import cn.tedu.charging.order.service.OrderService;
import cn.tedu.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("order")
@Api(tags = "订单模块")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private DeviceClient deviceClient;

    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult createOrder(@RequestBody OrderAddParam orderAddParam){
        log.debug("创建订单-入参:{}", orderAddParam);
        //创建类型的接口 是否要返回出参？要根据业务来决定
        //业务要求 用户创建订单后，跳转到订单详情页
        //创建订单接口的 出参 应该返回 订单号
        //订单号 可以 作为订单详情页的入参
        log.debug("创建订单-orderService:入参:{}", orderAddParam);
        String orderNo = orderService.createOrder(orderAddParam);
        log.debug("创建订单-orderService:入参:{},出参:{}", orderAddParam,orderNo);
        JsonResult<String> result = new JsonResult<>();
        result.setCode(2000);
        result.setData(orderNo);
        result.setMessage("创建订单成功");
        log.debug("创建订单入参:{},出参:{}", orderAddParam, result);
        return result;
    }
}
